package com.dragon.backstage.controller;

import com.dragon.backstage.domain.param.userOperateLog.UserOperateLogParam;
import com.dragon.backstage.domain.vo.userOperateLog.UserOperateLogDetailVo;
import com.dragon.backstage.domain.vo.userOperateLog.UserOperateLogVo;
import com.dragon.backstage.service.UserOperateLogService;
import com.dragon.common.annotation.AuthPermission;
import com.dragon.common.annotation.UserOperatorLog;
import com.dragon.common.domain.vo.PaginationVo;
import com.dragon.common.enums.BusinessType;
import com.dragon.common.utils.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * <p>
 * 操作日志记录 前端控制器
 * </p>
 *
 * @author dragon
 * @since 2024-08-01 18:08:50
 */
@RestController
@RequestMapping("/api/system/userOperateLog")
@Tag(name = "用户操作日志模块接口")
public class UserOperateLogController {

    @Resource
    private UserOperateLogService userOperateLogService;


    /**
     * 用户操作日志列表
     */
    @GetMapping("/list")
    @Operation(summary = "用户操作日志列表")
    @AuthPermission(value = "system.user.operate.log.list")
    public AjaxResult<PaginationVo<UserOperateLogVo>> list(UserOperateLogParam userOperateLogParam) {
        return userOperateLogService.userOperateLogList(userOperateLogParam);
    }

    /**
     * 用户操作日志详情
     */
    @GetMapping("/detail")
    @Operation(summary = "用户操作日志详情")
    @AuthPermission(value = "system.user.operate.log.detail")
    public AjaxResult<UserOperateLogDetailVo> detail(@RequestParam(value = "operateId", required = false) Long operateId) {
        return userOperateLogService.userOperateLogDetail(operateId);
    }

    /**
     * 删除用户操作日志
     */
    @DeleteMapping("/delete")
    @Operation(summary = "删除用户操作日志")
    @AuthPermission(value = "system.user.operate.log.delete")
    @UserOperatorLog(title = "用户操作日志", businessType = BusinessType.DELETE)
    public AjaxResult<Void> delete(@RequestParam(value = "operateIds", required = false) Long[] operateIds) {
        return userOperateLogService.deleteUserOperateLog(operateIds);
    }

    /**
     * 导出用户操作日志
     */
    @GetMapping("/export")
    @Operation(summary = "导出用户操作日志")
    @AuthPermission(value = "system.user.operate.log.export")
    @UserOperatorLog(title = "用户操作日志", businessType = BusinessType.EXPORT)
    public void export(HttpServletResponse response, UserOperateLogParam userOperateLogParam) throws IOException {
        userOperateLogService.exportUserOperateLog(response, userOperateLogParam);
    }

    /**
     * 清空用户操作日志
     */
    @DeleteMapping("/clean")
    @Operation(summary = "清空用户操作日志")
    @AuthPermission(value = "system.user.operate.log.clean")
    @UserOperatorLog(title = "用户操作日志", businessType = BusinessType.CLEAN)
    public AjaxResult<Void> clean() {
        return userOperateLogService.cleanUserOperateLog();
    }

}
